package com.lagou;

import com.lagou.service.UserServiceImpl;
import com.lagou.util.CustomerDataSource;
import com.lagou.util.MyZkSerializer;
import org.I0Itec.zkclient.ZkClient;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.beans.PropertyVetoException;

@SpringBootApplication
public class ServerBootstrap {

    public static ZkClient zkClient = new ZkClient("127.0.0.1:2181");

    public static void main(String[] args) throws InterruptedException, PropertyVetoException {
        int port = 8990;
        if(args[0]!=null){
            port = Integer.parseInt(args[0]);
        }
        zkClient.setZkSerializer(new MyZkSerializer());
        CustomerDataSource.init();
        SpringApplication.run(ServerBootstrap.class, args);
        UserServiceImpl.startServer("127.0.0.1",port);

        if(!zkClient.exists("/provider")){
            zkClient.createPersistent("/provider");
        }
        zkClient.createEphemeral("/provider/127.0.0.1:"+port);
    }



}
